<?php


namespace App\Controller\Api;

use App\Service\BankPay\BankPayService;
use App\Service\Dispatch\ChannelDispatchService;
use App\Service\RiskCheck\CommonRiskCheckService;
use App\Service\RiskRuleParamService;
use App\Utils\CustomUtils;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Utils\Arr;

/**
 * Class BankPayController
 * 银行网关支付
 *
 * @package App\Controller\Api
 * @Controller(prefix="/api/bankPay")
 */
class BankPayController extends BaseController {

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    /**
     * @Inject()
     * @var BankPayService
     */
    protected $BankPayService;

    public function __construct (LoggerFactory $loggerFactory) {
        // 第一个参数对应日志的 name, 第二个参数对应 config/autoload/logger.php 内的 key
        $this->logger = $loggerFactory->get('log', 'default');
    }

    /**
     * 支付
     *
     * @param RequestInterface $request
     * @PostMapping(path="doPay")
     *
     * @return array
     */
    public function doPay (RequestInterface $request) {

        $this->_validOrFail($request->all(), [
            'channelNo' => 'required',
        ]);

        $params = $request->post();

        return $this->BankPayService->doPay($params);
    }

    /**
     * 订单查询
     *
     * @param RequestInterface $request
     * @PostMapping(path="doOrderQuery")
     *
     * @return array
     */
    public function doOrderQuery (RequestInterface $request) {

        $this->_validOrFail($request->all(), [
            // 'channel' => 'required',
        ]);

        $params = $request->post();

        return $this->BankPayService->doOrderQuery($params);
    }

    /**
     * 退款
     *
     * @param RequestInterface $request
     * @PostMapping(path="doRefund")
     *
     * @return array
     */
    public function doRefund (RequestInterface $request) {

        $this->_validOrFail($request->all(), [
            // 'channel' => 'required',
        ]);

        $params = $request->post();

        return $this->BankPayService->doRefund($params);
    }

    /**
     * 退款查询
     *
     * @param RequestInterface $request
     * @PostMapping(path="doRefundQuery")
     *
     * @return array
     */
    public function doRefundQuery (RequestInterface $request) {

        $this->_validOrFail($request->all(), [
            // 'channel' => 'required',
        ]);

        $params = $request->post();

        return $this->BankPayService->doRefundQuery($params);
    }

    /**
     * 转帐
     *
     * @param RequestInterface $request
     * @PostMapping(path="doTransfer")
     *
     * @return array
     */
    public function doTransfer (RequestInterface $request) {

        $this->_validOrFail($request->all(), [
            // 'channel' => 'required',
        ]);

        $params = $request->post();

        return $this->BankPayService->doTransfer($params);
    }

    /**
     * 转帐查询
     *
     * @param RequestInterface $request
     * @PostMapping(path="doTransferQuery")
     *
     * @return array
     */
    public function doTransferQuery (RequestInterface $request) {

        $this->_validOrFail($request->all(), [
            'channel' => 'required',
        ]);

        $params = $request->post();

        return $this->BankPayService->doTransferQuery($params);
    }

}
